﻿using System;
using System.ComponentModel;
using XCI.Core;
using XCI.Extensions;

namespace XCI.Windows
{
    [System.ComponentModel.DesignerCategory("Code")]
    public partial class XtraReportx : DevExpress.XtraReports.UI.XtraReport
    {
        public XtraReportx()
        {
            InitializeComponent();
        }

        [Category("XCI"), Description("报表数据加载事件")]
        public event EventHandler<XtraReportDataSourceLoadEventArgs> ReportDataSourceLoad;

        private void XtraReport1_ParametersRequestSubmit(object sender, DevExpress.XtraReports.Parameters.ParametersRequestEventArgs e)
        {
            if (ReportDataSourceLoad == null) return;

            var map = new Map();
            foreach (var item in e.ParametersInformation)
            {
                map.Add(item.Parameter.Name, item.Parameter.Value.ToStringOrEmpty());
            }

            var args = new XtraReportDataSourceLoadEventArgs
            {
                Report = this,
                Param = map
            };

            ReportDataSourceLoad.Invoke(sender, args);
        }
    }

    public class XtraReportDataSourceLoadEventArgs : EventArgs
    {
        public XtraReportx Report { get; set; }
        public Map Param { get; set; }
    }
}
